<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('finance_customer_bills', function (Blueprint $table) {
            $table->id();

            $table->unsignedInteger('customer_id')->comment('客户id');
            $table->string('company_name')->nullable()->comment('客户公司名');
            $table->tinyInteger('bill_type')->default(1)->comment('1自然月，2非自然月');
            $table->string('bill_month')->nullable()->comment('预账单周期(月份)');
            $table->char('bill_date',16)->nullable()->comment('账单日期:年月');
            $table->string('bill_code')->nullable()->comment('账单月编码：Ym+customer_id');
            $table->date('bill_period_start')->nullable()->comment('账单期开始时间');
            $table->date('bill_period_end')->nullable()->comment('账单期结束时间');
            $table->tinyInteger('bill_status')->default(0)->comment('账单状态：默认0预账单，1提交审核（待审），2正式账单');
            $table->unsignedInteger('total_service_days')->nullable()->comment('服务天数');
            $table->unsignedInteger('total_consult')->nullable()->comment('总咨询量');
            $table->unsignedInteger('day_average_consult')->nullable()->comment('日均咨询量');
            $table->decimal('this_period_total',12,1)->nullable()->comment('本期费用合计');
            $table->decimal('previous_period_receivable',12,1)->nullable()->comment('上期应收金额');
            $table->decimal('received_total',12,1)->nullable()->comment('回款金额');
            $table->decimal('total_customer_pay',12,1)->nullable()->comment('本期应收客户金额');
            $table->text('bill_imgs')->nullable()->comment('账单附属图片');
            $table->tinyInteger('data_fill_status')->default(0)->comment('数据填报状态：默认0待审核，1已审核');
            $table->string('settlement_group')->nullable()->comment('账单结算群');

            $table->decimal('customer_actual_pay',12,1)->nullable()->comment('客户实付');
            $table->decimal('not_received_amount',12,1)->nullable()->comment('未收');
            $table->decimal('add_amount',12,1)->nullable()->comment('增收');
            $table->decimal('extra_refund',12,1)->nullable()->comment('补退');
            $table->decimal('extra_receive',12,1)->nullable()->comment('补收');
            $table->decimal('waste_amount',12,1)->nullable()->comment('损耗');
            $table->tinyInteger('clear_status')->default(0)->comment('默认0未结清，1已结清');

            $table->text('bill_description')->nullable()->comment('账单下面的文字说明');
            $table->unsignedInteger('total_consult_days')->nullable()->comment('总天数');

            $table->timestamps();
        });
        \DB::statement("ALTER TABLE `finance_customer_bills` comment '客户账单'");
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('finance_customer_bills');
    }
};
